A microprocessor consisting of a central process unit (CPU), an input-output port (I/O) and a memory is often adopted to be used for automatic control or signal processing. The microprocessors 8051 and 6811 are well-known 8-bit microprocessors. Although the internal structure of these kinds of 8-bit microprocessor (i.e. only providing a method for dividing a 8-bit dividend by a 8-bit divisor to obtain a 8-bit quotient and a 8-bit remainder) belongs to 8 bits, a long-bit (16 bits) division can be processed by using software programs.
Generally, a binary division can use a so-called shift-dividing method. For example, the steps for dividing 35 by 6 are described as follows:
First of all, to define the dividend, divisor, and quotient as follows:
dividend: 100011 quotient: 0 PA1 divisor: 110 PA1 dividend: 100011 quotient: 00 PA1 divisor: 0110 PA1 dividend: 001011 quotient: 001 PA1 divisor: 00110 PA1 dividend: 001011 quotient: 0010 PA1 divisor 000110 PA1 remainder: 000101 quotient: 00101 PA1 divisor 000110
Next, to compare the first 3 bits of the dividend 100 with the divisor 110. Since 100 is less than 110, i.e. it is not sufficient to be substracted, the quotient is leftwardly shifted one bit to be added `0` for obtaining a new quotient 00, but the dividend is leftwardly shifted one bit or the divisor is rightwardly shifted one bit for proceeding the next shift-dividing method. Now, the dividend, the divisor, and the quotient are as follows,
Because 110 is sufficient enough to be subtracted from 000 and is equal to 0010, the quotient is leftwardly shifted one bit and is added `1` into to obtain a new quotient 001. 1000 is replaced by the subtraction result 0010 for obtaining a new dividend 001011. After the divisor is rightwardly shifted one bit, the dividend, the divisor, and the quotient are become as follows:
Similarly, 101 is less than 110 so that it is not enough to be subtracted. The quotient will be leftwardly shifted one bit to be added `0` for obtaining a new quotient 010, and the divisor will be rightwardly shifted one bit. So, the quotient, the divisor and the dividend are as follows:
Finally, 1011 substrated from 110 is equal to 101. Because 1011 is not less than 110, the quotient will be leftwardly shifted one bit to be added `1` for obtaining a new quotient 00101 and the the partial dividend 1011 will be replaced by 0101. The last dividend is the last remainder. That is, 35 is divided by 6 to obtain the remainder 000101 (5) and the quotient 00101 (5). The results are described as follows:
According to the above description, the binary division is quite regular and the method for dividing 16-bit number by 8-bit number may operated by taking advantage of a software program.
Now, 8051 is used as an example. Since 8051 is a 8-bit microprocessor which only provides 8-bit division, a software program should be used for dividing 16-bit number by 8-bit number. Because each of 8051 registers is belonged to 8-bit, the 16-bit number must be stored in two registers. Here, a 16-bit digital data means a long bit digital data and a 8-bit digital data is a short bit digital data.
As shown in FIG. 1, 8051 microprocessor include a register set 18 and a flag set 19. In the register set 18, registers R0, R1, R2, R3, R4, R5, R6, R7 are usually used for data storage, the register A is a accumulator and often used for arithmetical and logical operation, and the rigister B is usually used for counting. In the flag set 19, bit C is a carry flag for shifting a register or adjudging arithmetical carry. The control program of the microprocessor is usually completed by Assembly Language. Registers, flags and instructions are used in the program of 8051 microprocessor to work.
As shown in FIG. 2 which is a flow chart showing the principle of the conventional division for a 8-bit microprocessor such as 8051 microprocessor.
Step 1: The high byte part of the dividend is stored in the rigister R1 and the low byte part of the dividend is stored in the rigister R2. A 16-bit digital number is divided by a 8-bit digital number to obtain the quotient (its maximum number is 16 bits) stored in the register R1 and R0. On the other hand, the maxmium bits of the remainder do not exceed 8 bits such that it is just stored in the register R6.
Step 2: Next, proceed initialization. The initial value of R6 is set on zero, and the counting value stored in the register B is set on 16 because there are 16 times of shifting action for 16-bit dividend.
Step 3: The Carry flag C must be clear befor executing the shifting action.
Step 4: The registers R1 and R0 are shifted one bit to the carry flag C.
Step 5: The register R1 is leftwardly and circularly shifted one bit into the register R6 by way of the carry flag C.
Step 6: Clear the carry flag C when the shifting action is completed.
Step 7: Compare the the register R6 and the register R2. If the value stored in the register R6 is smaller than the value stored in the register R2, step 10 will be executed to down count the counting value stored in the register B, that is, B=B-1.
Step 8: If the value stored in the register R6 is greater than the value stored in the register R2, the value stored in the register R2 is subtracted from the value stored in the register R6 to renew the value stored in the register R6.
Setp 9: Add `1` into the quotient to be stored in the register R0.
Step 10: Count down the counting value.
Step 11: Judge whether the registers R1 and R0 have been shifted 16 times according to the counting value. If B=0, it means that the operation have been completed, if not, the operation will return to step 3 to clear the carry flag C.
In the conventional method for dividing the 16-bit number by the 8-bit number, the total bit shifting for R1, R0 and R6 is 24 bits, that is, the number of bit shift is up to 24*16=384 times. Although the conventional method has a simple design, it does not take the operation speed into consideration. Due to the frequent bit shifting operation, the conventional dividing method can not meet the requirement of high speed, e.g. voice processing.